package com.example.cs_jump.Util;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.cs_jump.Adapater.ListViewAdapter;
import com.example.cs_jump.Bean.JsonBean;
import com.example.cs_jump.DetailedActivity;

public class ManagerAdapter {

    private static ListViewAdapter adapter;
    private static LinearLayoutManager manager;

    public static void setManagerOrAdapter(RecyclerView recyclerView, Context context, String name) {
        manager = new LinearLayoutManager(context.getApplicationContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        manager.setReverseLayout(false);
        recyclerView.setLayoutManager(manager);

        adapter = new ListViewAdapter(
                SqliteHelper.queryData(
                        context.getApplicationContext(), name),
                context.getApplicationContext());

        adapter.setHasStableIds(true);
        recyclerView.setAdapter(adapter);
        recyclerView.setAnimation(null);
        adapter.setOnItemClickListener(new ListViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClickListener(View view, JsonBean datas) {
               // Toast.makeText(context.getApplicationContext(), "单击了我" + recyclerView.getChildAdapterPosition(view), Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(context.getApplicationContext(), DetailedActivity.class);
                    intent.putExtra("title",datas.getTitle());
                    intent.putExtra("id",datas.getId());
                    intent.putExtra("brief",datas.getBrief());
                    intent.putExtra("tickrate",datas.getTickrate());
                    intent.putExtra("cover",datas.getCover());
                    context.startActivity(intent);
            }
        });
    }

    public static void getFilter(CharSequence CharSequence) {
        adapter.getFilter().filter(CharSequence);
    }
}
